<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教练员信息修改</title>
    <link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
    <script src="../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../res/js/Tools.js"></script>
    <script src="../res/layui/layui.js"></script>
    <script type="text/javascript">
        $.ajaxSettings.async = false;
    </script>
</head>
<body>
    <div id="Beboos">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>教练员信息管理</legend>
        </fieldset>
        <form id="form" class="layui-form">
            <!-- 用户ID -->
            <div style="display: none">
                <label class="layui-form-label">用户ID</label>
                <div>
                    <input type="text" name="usId" id="usId"  placeholder="用户ID" class="layui-input">
                </div>
            </div>
            <!-- 教练ID -->
            <div  style="display: none">
                <label class="layui-form-label">教练ID</label>
                <div>
                    <input type="text" name="coachId" id="coachId"  placeholder="教练ID" class="layui-input">
                </div>
            </div>
            <!-- 用户名 -->
            <div id="namediv" class="layui-form-item" >
                <div class="layui-inline">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="coachName" id="coachName" lay-verify="required"  placeholder="姓氏名称" class="layui-input">
                    </div>
                </div>
            <!-- 登陆账号 -->
                <div class="layui-inline">
                    <label class="layui-form-label">登陆账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="usName"   id="usName"  placeholder="登陆账号" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <!-- 用户电话 -->
                <div id="uphone" class="layui-inline">
                    <label class="layui-form-label">联系电话</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone" id="usPhone" lay-verify="required"  placeholder="联系电话" class="layui-input">
                    </div>
                </div>
                <!-- 登陆密码 -->
                <div id="upass" class="layui-inline">
                    <label class="layui-form-label">登陆密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="usPass" id="usPass"  placeholder="登陆密码" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <!--用户邮箱 -->
                <div id="uemil" class="layui-inline">
                    <label class="layui-form-label">用户邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="usEmail" id="usEmail" lay-verify="required" placeholder="用户邮箱" class="layui-input">
                    </div>
                </div>
                <!-- 头像 -->
                <div id="uphoto" class="layui-inline">
                    <label class="layui-form-label">用户头像</label>
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="test1">
                            <i class="layui-icon">&#xe67c;</i>点击上传图片
                        </button>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <!-- 部门名称 -->
                <div id="udeptName" class="layui-inline">
                    <label class="layui-form-label">部门名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="deptName" id="deptName"  placeholder="部门名称" class="layui-input">
                    </div>
                </div>
                <!-- 岗位名称 -->
                <div id="upostName" class="layui-inline">
                    <label class="layui-form-label">岗位名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="postName" id="postName"  placeholder="岗位名称" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <!-- 所在公司 -->
                <div id="uorganName" class="layui-inline">
                    <label class="layui-form-label">所在公司</label>
                    <div class="layui-input-block">
                        <input type="text" name="organName" id="organName"  placeholder="所在公司" class="layui-input">
                    </div>
                </div>
                <!-- 专业 -->
                <div id="uexpertSpecia" class="layui-inline">
                    <!--<div id="coaName">
                        <select lay-verify="required" id="expertSpecia" name="expertSpecia"  lay-search>
                            <option value="">请选择</option>
                        </select>
                    </div>-->
                    <div class="layui-inline">
                        <label class="layui-form-label">专业</label>
                        <div class="layui-input-block">
                            <select lay-verify="required" id="expertSpecia" name="expertSpecia"  lay-search>
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <!-- 通讯地址 -->
                <div id="ucoachExp" class="layui-inline">
                    <label class="layui-form-label">通讯地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="addr" id="addr" lay-verify="required" style="width: 140%" placeholder="通讯地址" class="layui-input">
                    </div>
                </div>
            </div>
            <!-- 备注 -->
            <div id="userRemark" class="layui-form-item">
                <label class="layui-form-label">其他说明</label>
                <div class="layui-input-block">
                    <textarea name="other" id="usRemark" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <!-- 提交 -->
            <div id="resubmit" class="layui-input-block">
                <button class="layui-btn"id="btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
            <!--<div id="conamediv">
                <label class="layui-form-label">专业</label>
            </div>-->
        </form>
        <div id="time" style="display: none">2</div><br>
    </div>
</body>
<script type="text/javascript">
    var form = null;
    //监听文件上传
    layui.use('upload', function(){
        var upload = layui.upload;
        //alert(JSON.stringify(formData));
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,auto: false //选择文件后不自动上传
            ,bindAction: '#formDemo' //指向一个按钮触发上传
            ,done: function(res){
                //上传完毕回调
                layer.msg(res.msg);
                //关闭当前层
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index);
            }
            ,error: function(){
                //alert("文件上传异常");
            }
        });
    });

    layui.use('form', function() {
        //myClose();
        form = layui.form;
        //监听提交按钮
        form.on('submit(formDemo)', function(data){
            //alert("表单提交了");
            //layer.msg(JSON.stringify(data.field)); //弹出当前表单数据*!/
            var formData = new FormData(document.getElementById("form"));
            var url = "../AtsEmpCoachAction/userInfo";

            $.ajax({
                type:"post",
                url:url,
                data:formData,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){

                    layer.msg(obj.msg,{icon:1,time:1000},function(){
                        //关闭当前层
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index);
                    });

                }
            })
            return false;
        });
        //加载专业选项
        loadSprot();
        //重新渲染
        form.render();
        //调用查询ID方法
        findById();
    })
    //监听文件上传
    layui.use('upload', function(){
        var upload = layui.upload;
        //参数
        //var formData = new FormData(document.getElementById("form"));
        //alert(JSON.stringify(formData));
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,auto: false //选择文件后不自动上传
            ,bindAction: '#btn' //指向一个按钮触发上传
            ,done: function(res){
                //上传完毕回调
                layer.msg(res.msg);
                //关闭当前层
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index);
            }
            ,error: function(){
                //alert("文件上传异常");
            }
        });
    });
    //加载专业选项
    function loadSprot(){
        form.render();
        $.ajax({
            url:"../AtsEmpCoachAction/loadSport",
            type:"post",
            dataType:"json",
            // contentType: "application/json;charset=utf-8",
            success:function(data){
                $.each(data,function(index,item) {
                   // $("#expertSpecia").append("<option value='"+item.sportId+"'>"+ item.sportName+"</option>")
                    $('#expertSpecia').append(new Option(item.sportName, item.sportId));// 下拉菜单里添加元素

                });
                layui.form.render("select");//渲染下拉框
            }

        });
    }

    //根据ID查询并根据ID是否存在限制登陆账号及密码
    function findById(){
        //layer.msg("嗯哼~~");
        var id = getQueryString("id");
        //alert("进入查询");
        if(id != null){
            $("#usName").attr("disabled",true);//限制账号
            $("#usPass").attr("disabled",true);//限制密码
        }
        $.ajax({
            url:"../AtsEmpCoachAction/findById",
            type:"post",
            data:{
                id:id
            },
            dataType:"json",
            // contentType: "application/json;charset=utf-8",
            success:function(data){
                $("#coachName").val(data.coachName);
                $("#usName").val(data.usName);
                $("#usPass").val(data.usPass);
                $("#usPhone").val(data.phone);
                $("#usEmail").val(data.usEmail);
                $("#deptName").val(data.deptName);
                $("#postName").val(data.postName);
                $("#organName").val(data.organName);
                $("#coachExp").val(data.coachExp);

                //alert(data.sportId);
                $("#expertSpecia").val(data.sportId);
                //alert(data.expertSpecia);
                $("#addr").val(data.addr);
                $("#usRemark").val(data.other);
                //绑定
                $("#usId").val(data.usId);
                $("#coachId").val(data.coachId);

                //alert(data.usId+"   "+data.coachId);
                form.render();//渲染
            }

        });
    }
</script>
</html>